﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    [Serializable]
    public class NhaCungCapDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion
        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion
        #region "Khai báo các Method"
        public bool InsertNCC(NhaCungCapDTO NhaCungCap)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaNCC", NhaCungCap.MaNCC);
            par[1] = new SqlParameter("@TenNCC", NhaCungCap.TenNCC);
            par[2] = new SqlParameter("@DiaChiNCC", NhaCungCap.DiaChiNCC);
            par[3] = new SqlParameter("@SoDTNCC", NhaCungCap.SoDTNCC);
            par[4] = new SqlParameter("@EmailNCC", NhaCungCap.EmailNCC);
            par[5] = new SqlParameter("@CongNoNCC", NhaCungCap.CongNoNCC);            
            
            if(!helper.InsertQuery("sp_Insert_NhaCungCap", par))                       
            {
                _error = helper.Error;
                return false;
            }
            return true;        
        }
        public bool UpdateNCC(NhaCungCapDTO NhaCungCap)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaNCC", NhaCungCap.MaNCC);
            par[1] = new SqlParameter("@TenNCC", NhaCungCap.TenNCC);
            par[2] = new SqlParameter("@DiaChiNCC", NhaCungCap.DiaChiNCC);
            par[3] = new SqlParameter("@SoDTNCC", NhaCungCap.SoDTNCC);
            par[4] = new SqlParameter("@EmailNCC", NhaCungCap.EmailNCC);
            par[5] = new SqlParameter("@CongNoNCC", NhaCungCap.CongNoNCC);
            if (!helper.UpdateQuery("sp_update_NhaCungCap", par))
            {
                _error = helper.Error;
                return false;
            }
            return true; 
        }
        public bool DeleteNCC(string maNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maNCC", maNCC);
            if (!helper.DeleteQuery("sp_Delete_NhaCungCap", par))
            {
                _error = helper.Error;
                return false;
            }
            return true; 
        }
        public DataSet LayDS_NhaCungCap()
        {
            helper = new Helper();
            DataSet ds_nv = helper.SelectQuery("sp_LayDS_NhaCungCap");
            return ds_nv;
        }
        #endregion
    }
}